from ..libmoops import int_to_twos, twos_to_int

class mdu(object):

    def __init__(self):
        self.hi=0
        self.lo=0
        self.divideByZero = 0
        
              
    def compute(self, mduOp, A, B):
        self.divideByZero = 0
        self.done = True
        if (mduOp == 0b01):                 #multhere #mult
            result = A*B
            print("~~")
            print(A)
            print("~~")
            if (result > 0xFFFFFFFF):        #if the result of multiplication is more than 32 bits
                self.lo = result & 0x00000000FFFFFFFF  #find the low 32 bits
                self.hi = (result >> 32) & 0x00000000FFFFFFFF #find the high 32 bits
            else:
                self.hi=0                #else result isn't 32 bits, and will fit into 16
                self.lo = result
        elif (mduOp == 0b10):               #div here, need t find the bits
            #self.lo = A/B
            if (B == 0):
                self.divideByZero = 1
            else:
                self.hi = A%B
                self.lo = int((A-self.hi)/B)
            
            
    def getDone (self):
        return self.done        
    def getLo(self):
        return self.lo
    def getHi(self):
        return self.hi
